package com.walking.controller;

import com.walking.entity.ActivityHelpEntity;
import com.walking.entity.ActivityInitiatorEntity;
import com.walking.entity.User;
import com.walking.manager.ActivityInitiatorManager;
import com.walking.repository.ActivityHelpRepository;
import com.walking.repository.ActivityInitiatorRepository;
import com.walking.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
@RestController
public class ActivityControler {
    @Autowired
    private ActivityInitiatorRepository activityInitiatorRepository;
    @Autowired
    private ActivityHelpRepository activityHelpRepository;
    @Autowired
    private UserRepository userRepository;

    @GetMapping("/assist")
    public void assist(String userToken) {
        ActivityInitiatorEntity byUserToken = activityInitiatorRepository.findByUserToken(userToken);
        ActivityInitiatorManager activityInitiatorManager = new ActivityInitiatorManager(byUserToken);

        ActivityHelpEntity byActivityId = activityHelpRepository.findByActivityId(byUserToken.getActivityId());

        Optional<User> byId = userRepository.findById(byUserToken.getCustNo());
        User user = byId.orElseGet(() -> null);
        activityInitiatorManager.assist(user == null ? false : true);

    }
}
